package leetcode_100;

/**
 *@author 周杨
 *RotateImage_48 90度旋转n^n矩阵 
 *describe: 先对角线旋转  再中轴旋转 AC 100%
 *2018年5月5日 下午5:49:09
 */
public class RotateImage_48 {
	public static void main(String[] args) {
		//int [][]nums=new int [][] {{1,2,3},{4,5,6},{7,8,9}};
		//int [][]nums=new int [][] {{1,2,3,4},{4,5,6,7},{7,8,9,10},{8,9,10,11}};
		int [][] nums=new int[][] {{1}};
		print(nums);
		rotate(nums);
		print(nums);
	}
	
	public static void print(int [][] nums) {
		for(int i=0;i<nums.length;++i) {
			for(int j=0;j<nums.length;++j) {
				System.out.print(nums[i][j]+" ");
			}
			System.out.println();
		}
	}
	public static void rotate(int[][] matrix) {
		int temp;
        for(int i=0;i<matrix.length-1;++i) {//对角线翻转
        	for(int j=i+1;j<matrix.length;++j) {
        		temp=matrix[i][j];
        		matrix[i][j]=matrix[j][i];
        		matrix[j][i]=temp;
        	}
        }
        int mid=matrix.length/2;
        for(int i=0;i<matrix.length;++i)//中轴旋转
        	for(int j=0;j<mid;++j) {
        		temp=matrix[i][j];
        		matrix[i][j]=matrix[i][matrix.length-j-1];
        		matrix[i][matrix.length-j-1]=temp;
        	}
    }
	
	public void help(int index) {
		
	}

}
